import logging

from fastapi import APIRouter, Depends

from like.schema_base import PageInationResult
from like.http_base import unified_resp
from .schemas import (
    TestListIn, TestExportIn, TestDetailIn, TestAddIn, 
    TestEditIn, TestDelIn, TestOut)
from .service import ITestService, TestService

logger = logging.getLogger(__name__)

router = APIRouter(prefix='/test')


@router.get('/list', response_model=PageInationResult[TestOut])
@unified_resp
async def test_list(
        list_in: TestListIn = Depends(),
        test_service: ITestService = Depends(TestService.instance)):
    """测试列表"""
    result = await test_service.list(list_in)
    result.file_name = "测试"
    return result

@router.get('/export', response_model=bytes)
@unified_resp
async def test_export(export_in: TestExportIn = Depends(), Test_service: ITestService = Depends(TestService.instance)):
    return await Test_service.export_excel(export_in)


@router.get('/detail')
@unified_resp
async def test_detail(
        detail_in: TestDetailIn = Depends(),
        test_service: ITestService = Depends(TestService.instance)):
    """测试详情"""
    return await test_service.detail(detail_in.id)


@router.post('/add')
@unified_resp
async def test_add(
        add_in: TestAddIn,
        test_service: ITestService = Depends(TestService.instance)):
    """测试新增"""
    return await test_service.add(add_in)


@router.post('/edit')
@unified_resp
async def test_edit(
        edit_in: TestEditIn,
        test_service: ITestService = Depends(TestService.instance)):
    """测试编辑"""
    return await test_service.edit(edit_in)


@router.post('/del')
@unified_resp
async def test_del(
        del_in: TestDelIn,
        test_service: ITestService = Depends(TestService.instance)):
    """测试删除"""
    return await test_service.delete(del_in.id)
